package com.app.base.service.system.service.impl;

import com.app.base.service.auth.service.SysUserService;
import com.app.base.service.system.entity.TemplateInfo;
import com.app.base.service.system.mapper.TemplateInfoMapper;
import com.app.base.service.system.service.TemplateInfoService;
import com.app.base.utlis.result.Result;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 模板表 服务实现类
 * @author yuhag
 * @since 2022-05-16
 */
@Service
@Slf4j
public class TemplateInfoServiceImpl extends ServiceImpl<TemplateInfoMapper, TemplateInfo> implements TemplateInfoService {

    @Resource
    private SysUserService userService;

    @Override
    public Result getTemplateList(String userId) {
        try{
            String companyId = userService.getCompanyId(userId);
            List<TemplateInfo> infoList = baseMapper.selectList(new QueryWrapper<TemplateInfo>()
                    .eq("company_id", companyId)
                    .orderByAsc("create_time"));

            return Result.ok(infoList);
        }catch(Exception e){
            log.error(e.getMessage());
            return Result.error(e.getMessage());
        }

    }
}
